package com.heima.article.listen;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.ArticleConfigService;
import com.heima.common.constants.WemediaConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@Slf4j
public class ArticleIsDownListen {
    @Autowired
    private ArticleConfigService articleConfigService;
    /**
     * 监听kafka的消息，上下架文章
     *
     * @param message
     */
    @KafkaListener(topics = WemediaConstants.WM_NEWS_UP_OR_DOWN_TOPIC)
    public void listenIsDown(String message) {
        //1、将message转为原来的map处理
        if (StringUtils.isNotBlank(message)) {
            Map map = JSON.parseObject(message, Map.class);
            articleConfigService.updateByMap(map);
        }
    }
}
